<template>
	<view>
		<msglist v-if="PageCur=='msglist'"></msglist>
		<myinfo v-if="PageCur=='myinfo'"></myinfo>
		
		<view class="cu-bar tabbar bg-white shadow foot">
			<view class="action" @click="NavChange" data-cur="msglist">
				<view :class="PageCur=='msglist'?'text-blue':'text-gray'">
					<view class="cuIcon-message"></view> 消息
				</view>
			</view>
			<view class="action"  @click="NavChange" data-cur="myinfo">
				<view class="cuIcon-cu-image"></view>
				<view :class="PageCur=='myinfo'?'text-blue':'text-gray'">
					<view class="cuIcon-homefill"></view> 我的
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Request from '../../lib/request.js'
	
	export default {
		data() {
			return {
				PageCur: ''
			}
		},
		onLoad(){
			let that = this;
			// 用户是否登录
			let uniIdToken = uni.getStorageSync('token')
			if (uniIdToken) {
				// 验证token
				Request.httpTokenRequest({url: 'Token/verifyToken',method: 'POST',}).then(res => {
					// 校验失败
					if(res.code != 1){
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 1000,
							success:function(){
								setTimeout(()=>{
									uni.reLaunch({
										url: '/pages/login/login'
									});
								},1000)
							}
						})
					}else{
						that.PageCur = 'msglist'
					}
                })
			} else {
				this.guideToLogin()
			}
		},
		methods: {
			guideToLogin() {
				uni.showModal({
					title: '未登录',
					content: '您未登录，需要登录后才能继续',
					showCancel: false,
					success: (res) => {
						if (res.confirm) {
							uni.reLaunch({
								url: '../login/login'
							});
						}
					}
				});
			},
			
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			}
		}
	}
</script>

<style>

</style>

